#region Using Statements
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner.Screens
{
    public class SkyBurnerScreenMain : SkyBurnerScreenBase
    {
        private enum MainMenuButtonID
        {
            btn_Start,
            btn_Highscores,
            btn_Config,
            btn_Credits,
            btn_Exit
        }

        private int m_currentSelection;
        private Texture2D m_buttonsTexture;
        private Texture2D m_focusTexture;
        private Texture2D m_titleTexture;
        private String[] m_itemCaption = new String[5] { "start", "hi scores", "config", "credits", "exit" };
        private float m_fOffset;
        private PostScreenEffectMotionBlur m_postScreenEffectMotionBlur;

        public SkyBurnerScreenMain(BaseGame game, ScreenManager pScreenManager, int nScreenID, bool bActive)
            : base(game, pScreenManager, nScreenID, bActive)
        {
            // setup texture...
            m_screenTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Screens\\SkyBurnerMainScreen2");
            m_buttonsTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Screens\\bw_buttons");
            m_focusTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Screens\\rect_focus");
            m_titleTexture = m_Game.ContentManager.Load<Texture2D>("Data\\Screens\\SkyBurnerTitle");

            // cicle through menus...
            m_currentSelection = 0;
            m_fOffset = 0.0f;
        }

        public override void Activate()
        {
            base.Activate();

            m_postScreenEffectMotionBlur = new PostScreenEffectMotionBlur(m_Game, 0.95f);
            m_Game.PostScreenEffectsManager.AddPostScreenEffect(m_postScreenEffectMotionBlur);            
        }

        public override void Deactivate()
        {
            base.Deactivate();

            m_Game.PostScreenEffectsManager.RemovePostScreenEffect(m_postScreenEffectMotionBlur);
        }

        public override void Update(GameTime gameTime, Camera pActiveCamera)
        {
            base.Update(gameTime, pActiveCamera);

            if (m_Game.UserInputState.IsUserAction(UserAction.Left))
            {
                m_currentSelection--;
                m_Game.SoundManager.PlaySound("Click");
            }
            else if (m_Game.UserInputState.IsUserAction(UserAction.Right))
            {
                m_currentSelection++;
                m_Game.SoundManager.PlaySound("Click");
            }
            else if (m_Game.UserInputState.IsUserAction(UserAction.Back))
            {
                m_Game.SoundManager.PlaySound("Click");
                m_Game.Exit();                
            }

            if (m_currentSelection < 0)
                m_currentSelection = 0;
            else if (m_currentSelection >= 5)
                m_currentSelection = 4;

            if (m_Game.UserInputState.IsUserAction(UserAction.ButtonA) || m_Game.UserInputState.IsUserAction(UserAction.RightTrigger))
            {
                m_Game.SoundManager.PlaySound("Highlight");

                switch ((MainMenuButtonID)m_currentSelection)
                {
                    case MainMenuButtonID.btn_Start:
                        {
                            m_screenManager.ActivateScreen(SkyBurnerScreenID.sbs_LevelChooser);
                            break;
                        }

                    case MainMenuButtonID.btn_Highscores:
                        {
                            m_screenManager.ActivateScreen(SkyBurnerScreenID.sbs_Highscores);
                            break;
                        }

                    case MainMenuButtonID.btn_Config:
                        {
                            m_screenManager.ActivateScreen(SkyBurnerScreenID.sbs_Config);
                            break;
                        }

                    case MainMenuButtonID.btn_Credits:
                        {
                            m_screenManager.ActivateScreen(SkyBurnerScreenID.sbs_Credits);
                            break;
                        }

                    case MainMenuButtonID.btn_Exit:
                        {
                            m_Game.Exit();
                            break;
                        }
                }
            }
            else
                SelectButtonByID(m_currentSelection);
        }

        public override void Draw(GameTime gameTime, Camera pActiveCamera)
        {
            base.Draw(gameTime, pActiveCamera);
          
            int nBaseX = (m_Game.GraphicsDevice.Viewport.Width - m_buttonsTexture.Width) / 2;
            m_Game.SpriteBatch.Begin();
            m_Game.SpriteBatch.Draw(m_buttonsTexture, new Vector2(nBaseX, 200), Color.White);

            m_Game.SpriteBatch.Draw(m_focusTexture, new Vector2(nBaseX + 128 * m_currentSelection, 184), new Color(255, 200, 0));

            m_Game.SpriteBatch.Draw(m_titleTexture, new Vector2(4.0f * (float)Math.Sin(m_fOffset) + (m_Game.GraphicsDevice.Viewport.Width - m_titleTexture.Width) / 2, 40 - 4.0f * (float)Math.Cos(m_fOffset)), new Color(255, 200, 0));
            m_Game.SpriteBatch.Draw(m_titleTexture, new Vector2(4.0f * (float)Math.Cos(m_fOffset) + (m_Game.GraphicsDevice.Viewport.Width - m_titleTexture.Width) / 2, 40 - 4.0f * (float)Math.Sin(m_fOffset)), new Color(255, 250, 0));

            m_Game.SpriteBatch.End();

            m_Game.BitmapFont.PrintCenterX(320, m_itemCaption[m_currentSelection], 16);
            m_Game.BitmapFont.PrintCenterX(570, "build " + m_Game.Version, 16);
            
            m_fOffset += 0.1f;
        }
    }
}
